package com.saret.dictionary;

import java.util.Collection;

public class Score {

    public static boolean valid(String a, String b) {
        int nlLength = size(a);
        int enLength = size(b);
        return !(2 * nlLength > 3 * enLength || 2 * enLength > 3 * nlLength);
    }

    private static int size(String a) {
        return a.replace("['|-]", " ").split("\\s+").length;
    }

    public static int max(int a, int b) {
        return a > b ? a : b;
    }

    public static double score(String nlLine,  Collection<String> nlWords) {

        int score = 0;

        int total = max(size(nlLine), nlWords.size());
        //to do: remove counted words from nlLine
        for (String nlWord : nlWords) {
            if (nlLine.toLowerCase().contains(nlWord.toLowerCase())) {
                score++;
            }
        }
        return (double) score / total;
    }

}
